package de.htwsaar.smog.dao;

import java.util.Date;
import java.util.List;
import java.util.Optional;

import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import de.htwsaar.smog.model.Measurement;

/**
 * @author Thomas Schoenfeld
 * @date 2015-02-14
 * @version 20150214_01
 * 
 * The interface MeasurementRepository provides the search functionality to access the database entries. 
 * This also means that we only support the "Read" functionality from CRUD at this time. 
 * 
 * Using the "findByFIELDNAME" pattern for its methods, the corresponding class is automatically created by Spring on runtime. 
 * This behavior follows the convention over configuration paradigm.
 *                    
 */
public interface MeasurementRepository extends Repository<Measurement, String> {

	/**
	 * Finds a measurement by its id.
	 * 
	 * @param id
	 *            id of the searched measurement
	 * @return the searched measurement
	 */
	Measurement findById(@Param("id") String id);

	/**
	 * Finds all measurements of a certain sensor id.
	 * 
	 * @param sensorId	searched sensor id
	 * @return			measurements of the searched sensor id
	 */
	List<Measurement> findBySensorId(String sensorId);
	
	/**
	 * Finds all measurements of a certain location.
	 * 
	 * @param location	searched location
	 * @return			measurements of the searched location
	 */
	List<Measurement> findByLocation(String location);
	
	/**
	 * Finds all measurements within a certain longitude.
	 * 
	 * @param longitude	searched longitude
	 * @return			measurements of the searched longitude
	 */
	List<Measurement> findByLongitude(String longitude);		
	
	/**
	 * Finds all measurements within a certain latitude.
	 * 
	 * @param latitude	searched latitude
	 * @return			measurements of the searched latitude
	 */
	List<Measurement> findByLatitude(String latitude);
	
	/**
	 * Finds all measurements of a certain measurement unit
	 * 
	 * @param type		searched measurement unit
	 * @return			measurements of the searched measurement unit
	 */
	List<Measurement> findByType(String type);
	
	/**
	 * Finds all measurements within a certain time.
	 * 
	 * @param time		searched time
	 * @return			measurements of the searched time
	 */
	List<Measurement> findByTime(Date time);
	
	/**
	 * Finds all measurements with a certain value.
	 * 
	 * @param value		searched value
	 * @return			measurements of the searched value
	 */
	List<Measurement> findByValue(int value);
		
	/**
	 * Provides all measurements inside the database.
	 * 
	 * @return			all measurements inside the database
	 */
	List<Measurement> findAll();
	
	/**
	 * Calls MongoDB findOne() method.
	 * 
	 * @param			value
	 * @return			the searched document
	 */
	Optional<Measurement> findOne(String value);

}
